
#include <vector>

class Solution {
 public:
  bool isPerfectSquare(int num)
  {
    if (num == 1) { return true; }
    long l = 1;
    long r = num / 2;

    while (l <= r)
    {
      long mid = (l + r) / 2;
      if (num < mid * mid)
      {
        r = mid - 1;
      } else if (num > mid * mid)
      {
        l = mid + 1;
      } else
      {
        return true;
      }
    }
    return false;
  }
};
